package com.datastructure.test.mirrorofbinarytree;

public class MirrorOfBinaryTree {
    public static void main(String[] args) {

    }
    public TreeNode Mirror (TreeNode pRoot) {
        // write code here
        handle(pRoot);
        return pRoot;
    }
    public void handle(TreeNode pRoot){
        TreeNode treeNode;
        if(pRoot.left!=null){
            handle(pRoot.left);
        }
        if(pRoot.right!=null){
            handle(pRoot.right);
        }
        if(pRoot.left!=null&&pRoot.right!=null){
            treeNode=pRoot.left;
            pRoot.left=pRoot.right;
            pRoot.right=treeNode;
        }else
        if(pRoot.left==null&&pRoot.right!=null){
            pRoot.left=pRoot.right;
            pRoot.right=null;
        }else
        if(pRoot.left != null){
            pRoot.right=pRoot.left;
            pRoot.left=null;
        }
    }

}
class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }
